package com.government.member.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.government.member.domain.UserHobby;
import com.government.member.mapper.UserHobbyMapper;
import com.government.member.service.UserHobbyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class UserHobbyServiceImpl implements UserHobbyService {
    @Autowired
    private UserHobbyMapper userHobbyMapper;

    @Override
    public List<UserHobby> getUserHobbyByUserId(Long userId) {

        return userHobbyMapper.getUserHobbyByUserId(userId);
    }

    /**
     * 用户收藏数量
     *
     * @return
     */
    @Override
    public int selectCollectCountByUserId(Long userId) {
        return userHobbyMapper.selectCount(Wrappers.<UserHobby>lambdaQuery().eq(UserHobby::getUserId, userId)
                .eq(UserHobby::getType, 2)
        );
    }

}
